package com.mccken.demo.io.netty.client;

import java.lang.reflect.Proxy;

/**
 * @program: mccken-collect
 * @description: 通过动态代理生成代理对象
 * @author: mccken
 * @create: 2022-04-30 22:09
 **/
public class BeanFactory {

	private NettyClient nettyClient;

	public BeanFactory(NettyClient nettyClient) {
		this.nettyClient = nettyClient;
	}

	public <T> T getBean(Class<T> clazz) {
		return (T) Proxy.newProxyInstance(
				Thread.currentThread().getContextClassLoader(),
				new Class<?>[]{clazz},
				new ClientInvocationHandler(nettyClient)
		);

	}
}
